package com.lagou.service.impl;

import com.lagou.annotation.Autowire;
import com.lagou.annotation.Service;
import com.lagou.annotation.Transactional;
import com.lagou.dao.AccountDao;
import com.lagou.factory.BeanFactory;
import com.lagou.pojo.Account;
import com.lagou.service.TransferService;
import com.lagou.utils.ConnectionUtils;

/**
 * <pre>
 * 描述：TODO
 * </pre>
 *
 * @类名：com.lagou.service.impl.TransferServiceImpl
 * @作者 mengwei
 * 创建日期：2020/10/13 15:15
 */
@Service("transferService")
public class TransferServiceImpl implements TransferService {

    @Autowire("accountDao")
    private AccountDao accountDao;
//
//    public void setAccountDao(AccountDao accountDao) {
//        this.accountDao = accountDao;
//    }
//
//    @Override
//    public AccountDao getAccountDao() {
//        return accountDao;
//    }

    @Transactional
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
//        ConnectionUtils.getInstance().getCurrentConnection().setAutoCommit(false);

        Account fromAccount = accountDao.queryAccountByCardNo(fromCardNo);
        Account toAccount = accountDao.queryAccountByCardNo(toCardNo);
        fromAccount.setMoney(fromAccount.getMoney() - money);
        toAccount.setMoney(toAccount.getMoney() + money);
        accountDao.updateAccountByCardNo(fromAccount);
        int i = 1 / 0;
        accountDao.updateAccountByCardNo(toAccount);
    }
}
